﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ASoft.Base;
using System.IO;

namespace ASoft.Web.Base
{
    public class WebRepository<T> : ARepository<T> where T : class,new()
    {
        protected override string AccessConnString
        {
            get
            {
                return string.Format(ConfigInfo.AccessConnectionString, Path.Combine(ConfigInfo.RootPath, "web.mdb"));
            }
        }

        public T GetById(int id)
        {
            if (id < 0)
            {
                return default(T);
            }
            return this.GetEntities(new Dictionary<string, string>() { { KeyName, id.ToString() } }).FirstOrDefault();
        }

        public T GetByCode(string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return default(T);
            }
            return this.GetEntities(new Dictionary<string, string>() { { "Code", code.Trim() } }).FirstOrDefault();
        }
    }
}
